package com.kaifamiao.jspcore;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.time.LocalDateTime;

@WebServlet("/sign/up")
public class SignUpServlet extends HttpServlet {

    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        request.setCharacterEncoding( "UTF-8" );

        String uname = request.getParameter("username");
        String passwd = request.getParameter("password");
        String gender = request.getParameter("gender");

        // 将 数据 设置到 请求属性 中
        request.setAttribute( "username" , uname );
        request.setAttribute( "password" , passwd );
        request.setAttribute( "gender" , gender );
        request.setAttribute( "time", LocalDateTime.now() );

        // 指定目标资源路径
        String path = "/scriptlet/result.jsp";
        // 获得可以去往指定路径的请求调度器
        RequestDispatcher rd = request.getRequestDispatcher( path );
        // 将请求和响应转发到指定资源
        rd.forward(request, response);
    }
}
